﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;

public partial class Admin_Holiday_HolidayManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //dllAuthentication.isAdminLogin();
        if (!IsPostBack)
        {            
            bindDropDownListYear(this.drpYear);
            bindGridView();
        }

    }

    /// <summary>
    /// 绑定年份DropDownList
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-1-12</date>
    void bindDropDownListYear(DropDownList _drp)
    {
        for (int i = 2009; i <= 2100; i++)
        {
            ListItem li = new ListItem(i.ToString());
            li.Value = i.ToString();
            _drp.Items.Add(li);
        }
        //根据系统日期自动绑定到当前年份
        string _year = DateTime.Now.Year.ToString();
        this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
    }

    void bindGridView()
    {
        HolidayMgr dllHolidayMgr = new HolidayMgr();
        object[] _value = new object[1];
        _value[0] = this.drpYear.SelectedItem.Text;
        DataTable dtHoliday = dllHolidayMgr.get(HolidayMgr.field.HolidayYear.ToString(), _value);
        this.gdvHoliday.DataSource = dtHoliday;
        this.gdvHoliday.DataBind();
    }


    /// <summary>
    /// 年份下拉列表事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindGridView();
    }


    /// <summary>
    /// 添加新节假日事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnAddHoliday_Click(object sender, EventArgs e)
    {
        string _year = this.drpYear.SelectedItem.Text;
        Utility.HttpHelp.redirectPage("Holiday_Add.aspx?Year=" + _year);
    }



    /// <summary>
    /// 删除节假日
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnHolidayDelete_Click(object sender, EventArgs e)
    {
        HolidayMgr dllHolidayMgr = new HolidayMgr();
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        object[] _value = new object[1];
        _value[0] = Convert.ToInt32(this.gdvHoliday.DataKeys[i]["HolidayId"].ToString());
        int result = dllHolidayMgr.del(HolidayMgr.field.HolidayId.ToString(), _value);
        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("删除节假日未成功，请重试！");
        }
        else
        {
            Response.Redirect("HolidayManager.aspx");
        }
    }
}
